/**************************************************************************
* This file is part of Hawkengine.
*
* Hawkengine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hawkengine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Hawkengine.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#ifndef _NETWORK_H_
#define _NETWORK_H_

/**************************************************************************
* Dependencies
**************************************************************************/
#include "engine/common.h"
 
/**************************************************************************
* Preprocessing
**************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

/**************************************************************************
* Types
**************************************************************************/
typedef enum
{
  NETWORK_PROTOCOL_TCP,
  NETWORK_PROTOCOL_UDP,
  NETWORK_PROTOCOL_COUNT,
} network_protocol_type;

typedef struct
{
  network_protocol_type protocol;
  int id;
  ULONG address;
  int port;
  BOOL connected;
  BOOL bound;
} network_type;

/**************************************************************************
* Variables
**************************************************************************/

/**************************************************************************
* Static Variables
**************************************************************************/

/**************************************************************************
* Function Prototypes
**************************************************************************/

/**************************************************************************
* Function Implementations
**************************************************************************/
BOOL network_bind(network_type* network, int port);
void network_close(network_type* network);
BOOL network_connect(network_type* network, const char* host, int port);
BOOL network_create(network_type* network, network_protocol_type protocol);
void network_init(void);
int network_receive(const network_type* network, network_type* client,
                    int max_bytes, UCHAR* data);
int network_send(const network_type* network, UCHAR* data, int bytes);
void network_uninit(void);
BOOL network_wait_for_client(const network_type* network, network_type* client);


#ifdef __cplusplus
}
#endif

#endif
